# Copyright (c) 2012 Nathan Grubb
# Available under the new BSD license; see LICENSE.txt

"""lib/config.py: Contains the Config object which is used to encapsulate interpretation
   of the configuration file.
"""

import os

class Config(object):
    def __init__(self, grubbot):
        self.grubbot = grubbot

        os.chdir(self.grubbot.grubbot_dir)
        global yaml
        yaml = __import__("yaml")

        self.config_path = os.path.join(self.grubbot.grubbot_dir, "config.yaml")

    def load(self):
        with open(self.config_path) as file:
            self.values = yaml.load(file.read())
        
        self.values["ops"] = dict(self.values["admins"].items() + self.values["ops"].items())

    def save(self):
        with open(self.config_path, "w") as file:
            file.write(yaml.dump(self.values))